#-------------------------------------------------------------------------------
# Name:       app
# Purpose:    TaskFile Register ExecuteTool
#
# Author:     SUPER_紫电  QQ,911344755
#
# Created:    09/02/2023
# Copyright:  (c) SUPER_紫电 2022 All rights reserved.
# Licence:    <Modified BSD License>
#-------------------------------------------------------------------------------

from trex import *

debug = False

start_fun = start

if not debug:
    module_name = 'trex_ext'
    module_path = '%s\\%s.py' % (common.get_startup_dir(), module_name)
    if os.path.exists(module_path):
        common.add_startup_dir()
        app = common.import_module(module_name)
        if app != None:
            start_fun = app.start

def main():
    if not taskfile.init_drv():
        print('Driver initialize %s!' % str(bool(taskfile.drv_initialized)).lower())
        return
    print('Driver initialize %s.' % str(bool(taskfile.drv_initialized)).lower())
    path = common.get_startup_dir()
    common.tempdir = path + common.tempdir
    common.workdir = common.tempdir
    if not os.path.exists(common.tempdir):
        os.makedirs(common.tempdir)
    set_ata_port()
    start_fun()
    taskfile.deinit_drv()
    mutex.release_mutex()

if __name__ == '__main__':
    main()
